package IO流复习;

import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;

public class fileReader {
    public static void main(String[] args)  {
        //使用hutool包
        cn.hutool.core.io.file.FileReader fileReader=new cn.hutool.core.io.file.FileReader("D:\\idea2022\\day.com.qiezi\\day_13\\src\\IO流复习\\a.txt");
        String s = fileReader.readString();
        System.out.println(s);


        cn.hutool.core.io.file.FileWriter f=new cn.hutool.core.io.file.FileWriter("D:\\idea2022\\day.com.qiezi\\day_13\\src\\IO流复习\\a.txt");
        f.append("我不好!");


        FileReader fr=null;
        try {
            fr = new FileReader("D:\\idea2022\\day.com.qiezi\\day_13\\src\\IO流复习\\a.txt");
            /*int d;
            while ((d=fr.read())!=-1){
                System.out.print((char)d);
            }*/

            char[] chars=new char[5];
            int b;
            while ((b=fr.read(chars))!=-1){
                for (int i = 0; i < b; i++) {
                    System.out.print(chars[i]);
                }
            }
        } catch (IOException e) {
            throw new RuntimeException(e);
        } finally {
            if (fr!=null){
                try {
                    fr.close();
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }}
    }
}
